package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsAdMapper;
import com.qf.pojo.DtsAd;
import com.qf.service.DtsAdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @version 1.0
 * @auther Administrator
 * @date 2023/2/25 8:49
 */
@Service
public class DtsAdServiceImpl implements DtsAdService {

    @Autowired
    private DtsAdMapper dtsAdMapper;

    /**
     * 广告显示
     * @param name
     * @param content
     * @param sort
     * @param order
     * @param page
     * @param limit
     * @return
     */
    @Override
    public IPage<DtsAd> findListByQuery(String name, String content, String sort, String order, Integer page, Integer limit) {

        return dtsAdMapper.selectPage(new Page<DtsAd>(page,limit)
                ,new QueryWrapper<DtsAd>()
                        .like(!StringUtils.isEmpty(name),"name",name)
                        .like(!StringUtils.isEmpty(content),"content",content)
                        .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort));
    }

    /**
     * 添加广告
     * @param dtsAd
     * @return
     */
    @Override
    public DtsAd create(DtsAd dtsAd) {
        dtsAdMapper.insert(dtsAd);
        return dtsAd;
    }

    /**
     * 编辑广告
     * @param dtsAd
     * @return
     */
    @Override
    public DtsAd update(DtsAd dtsAd) {
        dtsAdMapper.updateById(dtsAd);
        return dtsAd;
    }

    /**
     * 删除广告
     * @param dtsAd
     * @return
     */
    @Override
    public DtsAd delete(DtsAd dtsAd) {
        dtsAdMapper.deleteById(dtsAd);
        return dtsAd;
    }
}
